package com.ygqh.baby.controller.mobile;

import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResponseEntity;
import com.ygqh.baby.model.YgProductCommentModel;
import com.ygqh.baby.service.YgProductCommentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 商品类评论
 *
 * @author ZhangSai
 */
@Controller
@RequestMapping("/app/productComent")
public class YgProductComentController extends BaseController {

    @Autowired
    private YgProductCommentService ygProductCommentService;

    @ResponseBody
    @RequestMapping("list")
    public Message list(Long productId, Long groupId, QueryInfo queryInfo) {
        List<YgProductCommentModel> list = ygProductCommentService.findModelList(queryInfo, groupId, productId);
        return Message.success(list);
    }


    @ResponseBody
    @RequestMapping("commentCount")
    public ResponseEntity commentCount(Long groupId) {
        int count = ygProductCommentService.commentCount(groupId);
        return ResponseEntity.success(count);
    }

    @ResponseBody
    @RequestMapping("commentList")
    public ResponseEntity commentList(Long groupId, QueryInfo queryInfo) {
        List<YgProductCommentModel> list = ygProductCommentService.findModelList(queryInfo, groupId, null);
        return ResponseEntity.success(list);
    }

    @ResponseBody
    @RequestMapping("commentListByProductCode")
    public ResponseEntity commentListByProductCode(QueryInfo queryInfo, String productCode, boolean showAll) {
        List<YgProductCommentModel> findModelList = ygProductCommentService.findModelListByProductCode(queryInfo, productCode, showAll);
        return ResponseEntity.success(findModelList);
    }

    @ResponseBody
    @RequestMapping("commentCountByProductCode")
    public ResponseEntity commentCountByProductCode(String productCode, boolean showAll) {
        int count = 0;
        if (StringUtils.isNotBlank(productCode)) {
            count = ygProductCommentService.countByProductCode(productCode, showAll);
        }
        return ResponseEntity.success(count);
    }
}
